package com.safeluck.scannerqcr.fragment.msg;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.safeluck.scannerqcr.R;
import com.safeluck.scannerqcr.adapter.ChatDetailAdapter;
import com.safeluck.scannerqcr.bean.Chat;



/**
 * ScannerQCR
 * Created by lzw on 2017/12/6. 17:04:43
 * 邮箱：632393724@qq.com
 * All Rights Saved! Chongqing AnYun Tech co. LTD
 */

public class MessageFragment extends BaseBackFragment {
    private static final String CHAT_DETAIL = "chat_detail";
    private Chat mChat;
    private RecyclerView mRecyclerView;
    private ChatDetailAdapter chatDetailAdapter;
    private Toolbar mToobar;
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Bundle arg = getArguments();
        if (arg != null){
            mChat = arg.getParcelable(CHAT_DETAIL);

        }
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.message_detail,container,false);
        initView(view);
        return attachToSwipeBack(view);
    }

    private void initView(View view) {
        mRecyclerView = view.findViewById(R.id.recy_chat_detail);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(_mActivity));
        mRecyclerView.setHasFixedSize(true);
        chatDetailAdapter = new ChatDetailAdapter(_mActivity);
        mRecyclerView.setAdapter(chatDetailAdapter);
        chatDetailAdapter.setDatas(mChat);
        mToobar = view.findViewById(R.id.toolbar);
        initToolbar(mToobar);


    }

    @Override
    public void onLazyInitView(@Nullable Bundle savedInstanceState) {
        super.onLazyInitView(savedInstanceState);
        if (mChat != null){
            mToobar.setTitle(mChat.name);
        }
    }

    public static MessageFragment newInstance(Chat chat){
        Bundle bundle = new Bundle();
        bundle.putParcelable(CHAT_DETAIL,chat);
        MessageFragment messageFragment = new MessageFragment();
        messageFragment.setArguments(bundle);

        return messageFragment;
    }


}
